package com.sunny.example.string;

import java.util.*;

public class HJ41_称砝码 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int num = scanner.nextInt();
            List<Integer> fmC = new ArrayList<>(num);
            List<Integer> fmN = new ArrayList<>(num);
            HashSet<Integer> result = new HashSet<>();
            result.add(0);
            int temp1 = num;
            int temp2 = num;
            while (temp1 > 0) {
                fmC.add(scanner.nextInt());
                temp1--;
            }
            while (temp2 > 0) {
                fmN.add(scanner.nextInt());
                temp2--;
            }

            for (int i = 0; i < fmC.size(); i++) {//遍历砝码种类
                int f = fmC.get(i);
                ArrayList<Integer> list = new ArrayList<>(result);
                for (int j = 1; j <= fmN.get(i); j++) {//遍历砝码个数
                    for (int k = 0; k < list.size(); k++) {//结果遍历
                        result.add(list.get(k) + f * j);
                    }

                }
            }
            System.out.println(result.size());

        }
    }
}
